function [VD VDO SD_max  SD_mean SD_sd] = evaluateSegmantation(segmantationFileName,groundTruthFileName)
%input:
%segmantationFileName - Manual segmentation file
%groundTruthFileName   -  Automatic segmentation file
%
%output:
% VD                Volume Difference
% VDO               Volume Overlap Difference
% SD_max        Surface Distance Max
% SD_mean     Surface Distance Mean
% SD_sd          Surface Distance  Standart Deviation


%% check function arguments
if (nargin ~=2)
    warning('wrong number of input arguments ( 2 args )');
    return;
end
%if (nargout ~=5)
  %  warning('wrong number of input arguments (5 args)');
   % return;
%end
struct = load_untouch_nii(segmantationFileName);
imgA = struct.img;
struct = load_untouch_nii(groundTruthFileName);
imgB = struct.img;

tmp = double(imgB(:,:,40));
figure(1);
imshow(tmp);
figure(2);
tmp = edge(tmp);
imshow(tmp);





%% clear output variables
VD=VolumeDiff(imgA,imgB);
VDO = VolumeOverlapDiff(imgA,imgB);

 SD_max=sdMAX(imgA,imgB);
 SD_mean=0; SD_sd=0;


end

function res = sdMAX(imgA,imgB)    

    d1 = bwdist(imgA);
    d2 = bwdist(imgB);        
    d3 = d1 .* int32(imgB);
    d4 = d2 .* int32(imgA);
   
    res = max(d3,d4);

end

function res = VolumeOverlapDiff(imgA,imgB)
tt = imgA | imgB;
tt2 = imgA & imgB;
res= sum(sum(sum(tt2))) / sum(sum(sum(tt)))
end

function res =  VolumeDiff(imgA,imgB)
counterA=sum(sum(sum(imgA)));
counterB=sum(sum(sum(imgB)));
res= abs( counterA-counterB);
end



